package io.gitee.caoxiaoyu97.util.findclass;

import java.lang.annotation.Annotation;
import java.util.Set;

/*********************************************************
 * 文件名称：FindClassUtil.java
 * 系统名称：cxycloud
 * 模块名称：io.gitee.caoxiaoyu97.messageconvert.io
 * 功能说明：
 * 开发人员 @author：caoxy31978
 * 开发时间 @date：2023/3/9 15:50
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class FindClassUtil {
    public static <T> Set<Class<? extends T>>  getClassByParentType(Class<T> parentType, String packageName){
        ResolverUtil<T> resolverUtil = new ResolverUtil<>();
        resolverUtil.find(new ResolverUtil.IsA(parentType), packageName);
        Set<Class<? extends T>> classSet = resolverUtil.getClasses();
        return classSet;
    }
    public static <T> Set<Class<? extends T>> getClassByAnnotation(Class<? extends Annotation> annotation,
                                                                      String packageName){
        ResolverUtil<T> resolverUtil = new ResolverUtil<>();
        resolverUtil.find(new ResolverUtil.AnnotatedWith(annotation), packageName);
        Set<Class<? extends T>> classSet = resolverUtil.getClasses();
        return classSet;
    }
    public static <T> Set<Class<? extends T>> getClassParentTypeAndAnnotation(Class<T> parentType,Class<? extends Annotation> annotation,
                                                                                 String packageName){
        ResolverUtil<T> resolverUtil = new ResolverUtil<>();
        resolverUtil.find(new ResolverUtil.Test(){
            @Override
            public boolean matches(Class<?> type) {
                return type != null && parentType.isAssignableFrom(type) && type.isAnnotationPresent(annotation);
            }
        }, packageName);
        Set<Class<? extends T>> mapperSet = resolverUtil.getClasses();
        return mapperSet;
    }
}
